# Maintainer: David Runge <dvzrv@archlinux.org>

_name=tidal
pkgname=haskell-tidal
pkgver=1.9.4
pkgrel=2
pkgdesc="A domain specific language for live coding pattern."
arch=(loong64 x86_64)
url="https://tidalcycles.org/"
license=(GPL3)
groups=(pro-audio)
depends=(
  ghc
  ghc-libs
  glibc
  haskell-clock
  haskell-colour
  haskell-hosc
  haskell-mwc-random
  haskell-network
  haskell-primitive
  haskell-random
  haskell-tidal-link
  haskell-vector
  supercollider
)
checkdepends=(haskell-microspec)
optdepends=('sc3-plugins: Examples using special UGens')
conflicts=(tidalcycles)
replaces=(tidalcycles)
source=(https://hackage.haskell.org/packages/archive/$_name/$pkgver/$_name-$pkgver.tar.gz)
sha512sums=('006d4895ea6db1fd9a246c519b95416123450449903433e153f7bb6113507edb5127383ed15cfd8633b98f373d7677b40b67ca143cc443509e05dd71cf9aa54b')
b2sums=('dd5e0b6e6dae2ac3d576af600ac9da0928681ed90a0698e7d09e02e3c412575708bc2c93d2fece86e75059dec087659805b0834b353bddd551ef0bdf598dd94a')

build() {
  local configure_options=(
    -O
    --datasubdir=$pkgname
    --disable-library-vanilla
    --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname
    --dynlibdir=/usr/lib
    --enable-executable-dynamic
    --enable-shared
    --enable-tests
    --ghc-option=-fllvm
    --prefix=/usr
    --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
  )

  cd $_name-$pkgver
  runhaskell Setup configure "${configure_options[@]}"
  runhaskell Setup build $MAKEFLAGS
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
  cd $_name-$pkgver
  runhaskell Setup test --show-details=direct
}

package() {
  cd $_name-$pkgver
  runhaskell Setup copy --destdir="$pkgdir"
  install -vDm 744 register.sh "$pkgdir/usr/share/haskell/register/$pkgname.sh"
  install -vDm 744 unregister.sh "$pkgdir/usr/share/haskell/unregister/$pkgname.sh"
}
